function Ind=double_cluster(D,row_label,column_label,dist_method,link_method)

%DOUBLE_CLUSTER Plots double cluster for rows and columns
%Syntax double_cluster(D,row_label,column_label)
%Description
%    D is data
%    row_label and column_label are the titles
%    dist_method and link_method are passed to PDIST and LINKAGE
%    default values are 'euclidean' and 'average'
%
% Example: M=rand(10,8);M(:,4:6)=M(:,4:6)+1;M(5:7,:)=M(5:7,:)+1;
%          double_cluster(M,'rows','columns')
%
% Jonas Almeida

if nargin<4;dist_method='euclidean';end
if nargin<5;link_method='average';end
set(0,'RecursionLimit',200);
[n,m]=size(D);
% Cluster columns
subplot(2,2,2)
[a,b,Iy]=dendrogram(linkage(pdist(D',dist_method),link_method),m);
if nargin>2;title(column_label);end
% Cluster rows
subplot(2,2,3)
[a,b,Ix]=dendrogram(linkage(pdist(D,dist_method),link_method),n);
view(-90,90)
if nargin>1;ax=axis;text((ax(2)-ax(1))/2,ax(4),[' ',row_label],'VerticalAlign','bottom','Rotation',90);end
% represent D
D=D(:,Iy);D=D(Ix(end:-1:1),:);
subplot(2,2,4)
imagesc(D)
ax=axis;axis([ax(1)-0.5,ax(2)+0.5,ax(3)-0.5,ax(4)+0.5]);axis off
% Compose image
G=get(figure(gcf));
set(G.Children(3),'Position',[0.25,0.80,0.70,0.15]); % columns dendrogram
set(G.Children(3),'Color','none')
set(G.Children(3),'FontSize',8)
set(G.Children(2),'Position',[0.05,0.05,0.15,0.70]); % rows dendrogram
set(G.Children(2),'Color','none')
set(G.Children(2),'FontSize',8)
set(G.Children(2),'YAxisLocation','right')
set(G.Children(2),'XAxisLocation','top')
set(G.Children(1),'Position',[0.25,0.05,0.70,0.70]);
Ind.Ix=Ix;Ind.Iy=Iy;
